﻿using BLL;
using CrystalDecisions.CrystalReports.Engine;
using IYAKASAPortal.rpt;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IYAKASAPortal.InfoEnter
{
    public partial class PrintPZSQB : System.Web.UI.Page
    {
        private ReportDocument document;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["JCLSH"] != null && !string.IsNullOrEmpty(Request["JCLSH"]))
            {
              string  strJCLSH = Request["JCLSH"].ToString();
              BindReportData(strJCLSH);
            }

        }

        private void BindReportData(string strJCLSH)
        {
            string strPath = Server.MapPath("~/rpt/CrystalReportJDCPZ.rpt");

            CrystalReportViewer1.ReportSource = GetSearchData(strJCLSH, strPath);
            CrystalReportViewer1.DataBind();
            CrystalReportViewer1.RefreshReport();
        }

        private ReportDocument GetSearchData(string strJCLSH, string rptPath)
        {
            document = new ReportDocument();
            document.Load(rptPath);
            string strSql = "";
            if (!string.IsNullOrEmpty(strJCLSH))
            {
                RESULT_VEHICLE_INFO_BLL bll = new RESULT_VEHICLE_INFO_BLL();
                RESULT_VEHICLE_INFO info = bll.GetModel(strJCLSH);

                DsJDCPZ ds = new DsJDCPZ();

                if (info != null)
                {
                    DataRow dr = ds.Tables["DtSQR"].NewRow();
           
                    dr["SYR"] = info.SYR;
                    dr["LXDZ"] = info.LXDZ;
                    dr["LXDH"] = info.LXDH;
                    dr["HPZL"] = info.HPZL;
                    dr["HPHM"] = info.HPHM;
                    dr["YZBH"] = info.YZBH;
                    dr["DLRDH"] = info.DLRLXDH;
                    dr["DLRMC"] = info.DLRMC;
                    dr["Y"] = DateTime.Now.Year;
                    dr["M"] = DateTime.Now.Month;
                    dr["D"] = DateTime.Now.Day;

                    ds.Tables["DtSQR"].Rows.Add(dr);
                    document.SetDataSource(ds);
                }
            }          
            return document;
        }

        protected override void OnUnload(EventArgs e)
        {
            document.Dispose();
            base.OnUnload(e);
        }
    }
}